package com.bw.module_home.widget

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import com.bw.module_home.databinding.HomeViewXiguatitlebarBinding

/**
 * @Author : ZhouZiYao
 * @Time : On 2023/11/24 11:38
 * @Description :
 */
class XiGuaTitleBar @JvmOverloads constructor(context: Context, attributes: AttributeSet):
    LinearLayout(context,attributes) {
    private val binding:HomeViewXiguatitlebarBinding= HomeViewXiguatitlebarBinding.inflate(
        LayoutInflater.from(context),this,true)
    init {
        removeAllViews()
        addView(binding.root)


        binding.vtViewXiguatitlebarTxt.setText(19.0f, 5, Color.LTGRAY) //设置属性,具体跟踪源码

        binding.vtViewXiguatitlebarTxt.setTextStillTime(3000) //设置停留时长间隔

        binding.vtViewXiguatitlebarTxt.setAnimTime(300) //设置进入和退出的时间间隔

        //对单条文字的点击监听
        binding.vtViewXiguatitlebarTxt.setItemClickListener(VerticalTextView.OnItemClickListener {
            callback?.onClick(it)
        })
    }

    /**
     * 设置数据源
     */
    fun setDataSource(list:MutableList<String>){
        binding.vtViewXiguatitlebarTxt.setTextList(list as ArrayList<String>?)
    }

    override fun onAttachedToWindow() {
        super.onAttachedToWindow()
        //   BadgeUtil.Badge(context,binding.ivViewXiguatitlebar,0)
        binding.vtViewXiguatitlebarTxt.startAutoScroll()
    }

    override fun onDetachedFromWindow() {
        super.onDetachedFromWindow()
        binding.vtViewXiguatitlebarTxt.stopAutoScroll()
    }







    private var callback:TitleBarClickCallback?=null

    /**
     * 设置点击回调
     */
    fun setOnClickCallback(_callback:TitleBarClickCallback){
        callback=_callback
    }

    interface TitleBarClickCallback{
        fun onClick(index:Int)
    }


}